import Vector2 from "../maths/Vector2";
import Math2D from "../maths/Math2D";
import Size from "./Size";

// 矩形包围框
export default class Rectangle {
    public origin: Vector2;
    public size: Size;

    public constructor(orign: Vector2 = new Vector2(), size: Size = new Size(1, 1)) {
        this.origin = orign;
        this.size = size;
    }

    public isEmpty(): boolean {
        let area: number = this.size.width * this.size.height;
        if (Math2D.isEquals(area, 0) === true) {
            return true;
        } else {
            return false;
        }
    }

    public static create(x: number = 0, y: number = 0, w: number = 1, h: number = 1): Rectangle {
        let origin: Vector2 = new Vector2(x, y);
        let size: Size = new Size(w, h);
        return new Rectangle(origin, size);
    }
}